package com.health.web.controller.teahouse;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.teahouse.domain.Fruits;
import com.health.teahouse.service.IFruitsService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;

/**
 * 水果信息管理Controller
 * 
 * @author yangzw
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/teahouse/fruits")
public class FruitsController extends BaseController
{
    @Autowired
    private IFruitsService fruitsService;

    /**
     * 查询水果信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:fruits:list')")
    @GetMapping("/list")
    public TableDataInfo list(Fruits fruits)
    {
        startPage();
        List<Fruits> list = fruitsService.selectFruitsList(fruits);
        return getDataTable(list);
    }

    /**
     * 导出水果信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('teahouse:fruits:export')")
    @Log(title = "水果信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Fruits fruits)
    {
        List<Fruits> list = fruitsService.selectFruitsList(fruits);
        ExcelUtil<Fruits> util = new ExcelUtil<Fruits>(Fruits.class);
        util.exportExcel(response, list, "水果信息管理数据");
    }

    /**
     * 获取水果信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('teahouse:fruits:query')")
    @GetMapping(value = "/{fruitId}")
    public AjaxResult getInfo(@PathVariable("fruitId") Long fruitId)
    {
        return success(fruitsService.selectFruitsByFruitId(fruitId));
    }

    /**
     * 新增水果信息管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:fruits:add')")
    @Log(title = "水果信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Fruits fruits)
    {
        return toAjax(fruitsService.insertFruits(fruits));
    }

    /**
     * 修改水果信息管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:fruits:edit')")
    @Log(title = "水果信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Fruits fruits)
    {
        return toAjax(fruitsService.updateFruits(fruits));
    }

    /**
     * 删除水果信息管理
     */
    @PreAuthorize("@ss.hasPermi('teahouse:fruits:remove')")
    @Log(title = "水果信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fruitIds}")
    public AjaxResult remove(@PathVariable Long[] fruitIds)
    {
        return toAjax(fruitsService.deleteFruitsByFruitIds(fruitIds));
    }
}
